package com.ruoyi.system.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.TmdDutyDatePeople;
import com.ruoyi.system.mapper.TmdDutyDatePeopleMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.TmdDutyApplicationMapper;
import com.ruoyi.system.domain.TmdDutyApplication;
import com.ruoyi.system.service.ITmdDutyApplicationService;
import com.ruoyi.common.core.text.Convert;
import org.springframework.transaction.annotation.Transactional;

/**
 * 排班申请Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-04-20
 */
@Service
public class TmdDutyApplicationServiceImpl implements ITmdDutyApplicationService 
{
    @Autowired
    private TmdDutyApplicationMapper tmdDutyApplicationMapper;
    @Autowired
    private TmdDutyDatePeopleMapper tmdDutyDatePeopleMapper;

    /**
     * 查询排班申请
     * 
     * @param id 排班申请主键
     * @return 排班申请
     */
    @Override
    public TmdDutyApplication selectTmdDutyApplicationById(Long id)
    {
        return tmdDutyApplicationMapper.selectTmdDutyApplicationById(id);
    }

    /**
     * 查询排班申请列表
     * 
     * @param tmdDutyApplication 排班申请
     * @return 排班申请
     */
    @Override
    public List<TmdDutyApplication> selectTmdDutyApplicationList(TmdDutyApplication tmdDutyApplication)
    {
        return tmdDutyApplicationMapper.selectTmdDutyApplicationList(tmdDutyApplication);
    }

    /**
     * 新增排班申请
     * 
     * @param tmdDutyApplication 排班申请
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public int insertTmdDutyApplication(TmdDutyApplication tmdDutyApplication,List<TmdDutyDatePeople> dutyDatePeopleList)
    {

        System.out.println(dutyDatePeopleList);
        tmdDutyApplication.setCreateTime(DateUtils.getNowDate());
        int i = tmdDutyApplicationMapper.insertTmdDutyApplication(tmdDutyApplication);
//        获取返回的id
        Long id = tmdDutyApplication.getId();
        System.out.println("返回值班申请id"+i);
//      设置值班申请id
        for (TmdDutyDatePeople eve:dutyDatePeopleList) {
            eve.setDutyApplicationId(id);
        }
//      插入值班日期、值班人
        tmdDutyDatePeopleMapper.insertTmdDutyDatePeopleList(dutyDatePeopleList);
        return i;
    }

    /**
     * 修改排班申请
     * 
     * @param tmdDutyApplication 排班申请
     * @return 结果
     */
    @Override
    public int updateTmdDutyApplication(TmdDutyApplication tmdDutyApplication)
    {
        return tmdDutyApplicationMapper.updateTmdDutyApplication(tmdDutyApplication);
    }

    /**
     * 批量删除排班申请
     * 
     * @param ids 需要删除的排班申请主键
     * @return 结果
     */
    @Override
    public int deleteTmdDutyApplicationByIds(String ids)
    {
        return tmdDutyApplicationMapper.deleteTmdDutyApplicationByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除排班申请信息
     * 
     * @param id 排班申请主键
     * @return 结果
     */
    @Override
    public int deleteTmdDutyApplicationById(Long id)
    {
        return tmdDutyApplicationMapper.deleteTmdDutyApplicationById(id);
    }

    @Override
    public List<TmdDutyApplication> getAllApp() {
        return tmdDutyApplicationMapper.getAllApp();
    }
}
